package com.esun.payment_api.dao;

import lombok.Data;

import java.io.Serializable;

@Data
public class AccessToken implements Serializable {

    private String accessToken;
    //过期时间 = 当前系统时间+微信传来的过期时间
    private Long expiresTime;

    public AccessToken(String accessToken, String expiresIn) {
        this.accessToken = accessToken;
        this.expiresTime = System.currentTimeMillis() + Integer.parseInt(expiresIn) * 1000;
    }

    /**
     * 判断token是否过期
     *
     * @return true or false
     */
    public boolean isExpired() {
        return System.currentTimeMillis() > expiresTime;
    }
}
